$('.log-top li').click(function () {

  console.log($(this));
  console.log($(this).index());

  $(this).css({ color: 'white' }).siblings().css({ color: '#9c9c9c' })
  $(this).addClass('log-top-active').siblings().removeClass('log-top-active');
  $('.log-main li').eq($(this).index()).addClass('log-main-active').siblings().removeClass('log-main-active');
})


let user2 = localStorage.getItem("user");
let pawd = localStorage.getItem("pawd");
// console.log(user2);
// console.log(pawd);
$('#user').val(user2);
$('#pawd').val(pawd);

let isUsername = true;
$('#user').blur(function () {
  let reg = /^[a-zA-Z]\w{5,17}$/;
  if (reg.test($('#user').val())) {
    $('#user').next().html('^_^');
    $('#user').next().css({ fontSize: '12px', color: 'green' });
    isUsername = true;

  } else {
    $('#user').next().html('账号必须以字母开头6-18个非空字符');
    $('#user').next().css({ fontSize: '12px', color: 'red' });
    isUsername = false;
  }
})

let isPassword = true;
$('#pawd').blur(function () {
  let reg = /^\S{3,10}$/;
  if (reg.test($('#pawd').val())) {
    // $('#pawd').next().html('密码长度为3-10个非空字符');
    $('#pawd').next().html('^_^');
    $('#pawd').next().css({ fontSize: '12px', color: 'green' });
    isPassword = true;

  } else {
    $('#pawd').next().html('密码长度为3-10个非空字符');
    $('#pawd').next().css({ fontSize: '12px', color: 'red' });
    isPassword = false;

  }

})


$('#btn').click(function () {
  // console.log(isUsername);

  // console.log(isPassword);
  if (isPassword && isUsername) {
    console.log(4);
    let url = "http://jx.xuzhixiang.top/ap/api/login.php";
    $.get(url, { username: $('#user').val(), password: $('#pawd').val() }).then(function (res) {
      console.log(res);
      if (res.code == 1) {
        localStorage.setItem("uid", res.data.id);


        logBtn.innerHTML = "欢迎回来!"
        boxLog.style.display = "none";



        // location.href = "index.html"


      }
    })
  }

})
let boxPosition = document.querySelector('.box-position');
let boxLog = document.querySelector('.box-log');
let logBtn = document.querySelector('.log-btn');
logBtn.onclick = function (evt) {
  evt.stopPropagation();
  boxLog.style.display = "block";

}
document.onclick = function () {
  boxLog.style.display = "none";
}
boxPosition.onclick = function (evt) {
  evt.stopPropagation();
}



let moveUp = document.querySelector('.top-left a');
// console.log(moveUp.offsetTop);
// let Y = moveUp.offsetTop;
let spend = 2;
let Y = moveUp.offsetTop;

moveUp.timer = setInterval(() => {


  moveUp.style.top = moveUp.offsetTop - spend + "px";
  if (moveUp.offsetTop <= -30) {
    // clearInterval(moveUp.timer)
    moveUp.style.top = "4px";
  }

}, 100);

